Imports TeamUp.Fachada
Imports TeamUp.Entidades

Public Class frmManterEscopo
    Dim blnFlagNovo As Boolean = False
    Dim lstProjeto As List(Of Projeto)

    Private Sub btnFechar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFechar.Click
        Close()
    End Sub

    Public Sub carregarComboProjeto()
        Dim objFachada As Facade

        Dim intContador As Integer = 0
        Try
            objFachada = Facade.getInstance()
            lstProjeto = objFachada.consultarProjeto(New Projeto("", ""))

            If Not lstProjeto Is Nothing Then
                cboProjeto.DataSource = lstProjeto
            End If

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "SEP")
        End Try
    End Sub

    Private Sub frmManterEscopo_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        carregarComboProjeto()
    End Sub

    Private Sub btnNovo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNovo.Click
        blnFlagNovo = True
    End Sub

    Private Sub btnSalvar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSalvar.Click
        Dim objFachada As Facade
        Try
            objFachada = Facade.getInstance()

            objFachada.incluirEscopo(New Escopo(txtDescricao.Text, txtPremissa.Text, Nothing, cboUnidade.Text, cboProjeto.SelectedValue, ""))


            carregarComboProjeto()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "SEP")
        End Try
    End Sub

    Private Sub cboProjeto_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboProjeto.SelectedIndexChanged
        Try
            grdEscopo.DataSource = lstProjeto.Item(cboProjeto.SelectedIndex).getListEscopo
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "SEP")
        End Try
    End Sub

    Private Sub btnExcluir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExcluir.Click
        Dim objFachada As Facade
        Try
            objFachada = Facade.getInstance()

            objFachada.excluirEscopo(New Escopo(txtDescricao.Text, txtPremissa.Text, Nothing, cboUnidade.Text, cboProjeto.SelectedValue, grdEscopo.Item("IdEscopo", grdEscopo.CurrentRow.Index).Value))

            carregarComboProjeto()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "SEP")
        End Try
    End Sub
End Class